package com.ifonly.logger.acl;

import com.ifonly.logger.Logger;
import org.apache.commons.logging.LogFactory;

/**
 * @author <a href="mailto:ifonlymaster@163.com">ifonly</a>
 * @version 1.0 2015-12-09 11:40
 * @since JDK 1.6
 */
public class ACLogger extends Logger {
    private org.apache.commons.logging.Log log;

    public ACLogger(String name) {
        this.name = name;
        this.log = LogFactory.getLog(name);
    }

    public ACLogger(Class<?> clazz) {
        this.name = clazz.getName();
        this.log = LogFactory.getLog(clazz);
    }

    @Override
    public boolean isEnabled(Level level) {
        boolean enabled;
        switch (level) {
            case TRACE:
                enabled = log.isTraceEnabled();
                break;
            case DEBUG:
                enabled = log.isDebugEnabled();
                break;
            case INFO:
                enabled = log.isInfoEnabled();
                break;
            case WARN:
                enabled = log.isWarnEnabled();
                break;
            case ERROR:
                enabled = log.isErrorEnabled();
                break;
            default:
                throw new IllegalArgumentException();
        }
        return enabled;
    }

    @Override
    public void log(Level level, String message) {
        switch (level) {
            case ERROR:
                log.error(message);
                break;
            case WARN:
                log.warn(message);
                break;
            case INFO:
                log.info(message);
                break;
            case DEBUG:
                log.debug(message);
                break;
            case TRACE:
                log.trace(message);
                break;
            default:
                throw new IllegalArgumentException();
        }
    }

    @Override
    public boolean isTraceEnabled() {
        return log.isTraceEnabled();
    }

    @Override
    public void trace(String message) {
        log.trace(message);
    }

    @Override
    public boolean isDebugEnabled() {
        return log.isDebugEnabled();
    }

    @Override
    public void debug(String message) {
        log.debug(message);
    }

    @Override
    public boolean isInfoEnabled() {
        return log.isInfoEnabled();
    }

    @Override
    public void info(String message) {
        log.info(message);
    }

    @Override
    public boolean isWarnEnabled() {
        return log.isWarnEnabled();
    }

    @Override
    public void warn(String message) {
        log.warn(message);
    }

    @Override
    public void warn(String message, Throwable throwable) {
        log.warn(message, throwable);
    }

    @Override
    public boolean isErrorEnabled() {
        return log.isErrorEnabled();
    }

    @Override
    public void error(String message) {
        log.error(message);
    }

    @Override
    public void error(String message, Throwable throwable) {
        log.error(message, throwable);
    }
}
